package com.moyun.finance.controller;

import com.moyun.finance.entity.OrgDept;
import com.moyun.finance.entity.OrgRole;
import com.moyun.finance.entity.Response;
import com.moyun.finance.service.OrgDeptService;
import com.moyun.finance.service.OrgRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/org/role")
public class OrgRoleController {
    @Autowired
    OrgRoleService ors;

    //部门新增
    @RequestMapping("/save")
    public @ResponseBody Response save(@RequestBody OrgRole role){
        Response res = ors.save(role);
        return res;
    }

    //部门修改
    @RequestMapping("/update")
    public @ResponseBody Response update(@RequestBody OrgRole role){
        Response res = ors.update(role);
        return res;
    }

    //部门删除
    @RequestMapping("/delete")
    public @ResponseBody Response delete(@RequestBody OrgRole role){
        Response res = ors.delete(role);
        return res;
    }

    //查询指定公司所有部门
    @RequestMapping("/findAllByCompanyId")
    public @ResponseBody Response findAllByDeptId(String companyId){
        List<OrgRole> roles = ors.findAll(companyId);
        return new Response("",roles,true);
    }

    //根据id查部门
    @RequestMapping("/findById")
    public @ResponseBody Response findOneById(String roleId){
        OrgRole role = ors.findOneById(roleId);
        return new Response("",role,true);
    }
}
